package com.wang.code;

import java.util.HashSet;
public class _6HashSetTest {

	public static void main(String[] args) {
		
		HashSet set = new HashSet();
		
		set.add(1);
		set.add(1);
		set.add("asd");
		set.add("zxv");
		set.add("xczv");
		System.out.println(set);
		
		System.out.println("=======================");
		Student stu1 = new Student("zhangsan","123456");
		Student stu2 = new Student("zhangsan","123456");
		
		System.out.println("stu1.hashCode() = " + stu1.hashCode());
		System.out.println("stu2.hashCode() = " + stu2.hashCode());
		System.out.println(stu1.equals(stu2));
		set.add(stu1);
		set.add(stu2);
		System.out.println(set);
		
	}

}

class Student{
	private String name;
	private String cellPhone;
	public Student() {
	}
	public Student(String name, String cellPhone) {
		super();
		this.name = name;
		this.cellPhone = cellPhone;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCellPhone() {
		return cellPhone;
	}
	public void setCellPhone(String cellPhone) {
		this.cellPhone = cellPhone;
	}
	@Override
	public String toString() {
		return "[" + name + ", " + cellPhone + "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cellPhone == null) ? 0 : cellPhone.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (cellPhone == null) {
			if (other.cellPhone != null)
				return false;
		} else if (!cellPhone.equals(other.cellPhone))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
}
